package demoMod.gdxform.abstracts;

import com.badlogic.gdx.graphics.Color;
import demoMod.gdxform.interfaces.Element;

/**
 * 元素抽象类，默认实现了一些常用的方法
 * 继承此类以减少重复的方法实现
 */
public abstract class AbstractElement implements Element {
    private String id;
    private Container<? extends Element> parent;
    private float x;
    private float y;
    private float width;
    private float height;
    private boolean resizable;
    private boolean visible;
    private boolean enabled;

    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    @Override
    public void update() {

    }

    @Override
    public Container<? extends Element> getParent() {
        return parent;
    }

    @Override
    public void setParent(Container<? extends Element> parent) {
        this.parent = parent;
    }

    @Override
    public float getX(boolean isAbsolute) {
        return isAbsolute && parent != null ? parent.getX(true) + x : x;
    }

    @Override
    public float getY(boolean isAbsolute) {
        return isAbsolute && parent != null ? parent.getY(true) + y : y;
    }

    @Override
    public void setX(float x) {
        this.x = x;
    }

    @Override
    public void setY(float y) {
        this.y = y;
    }

    @Override
    public float getWidth() {
        return width;
    }

    @Override
    public float getHeight() {
        return height;
    }

    @Override
    public void setWidth(float width) {
        this.width = width;
    }

    @Override
    public void setHeight(float height) {
        this.height = height;
    }

    @Override
    public Color getBackground() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void setBackground(Color background) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isResizable() {
        return resizable;
    }

    @Override
    public void setResizable(boolean resizable) {
        this.resizable = resizable;
    }

    @Override
    public boolean enabled() {
        return enabled;
    }

    @Override
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    @Override
    public boolean visible() {
        return visible;
    }

    @Override
    public void setVisible(boolean visible) {
        this.visible = visible;
    }
}
